﻿<%@ Page Title="Ultimate Vacation Experience CMS :: User Management" Language="C#" MasterPageFile="~/Admin/Admin.Master" AutoEventWireup="true" CodeBehind="UserManagement.aspx.cs" Inherits="TravelSite.Admin.UserManagement" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript">
        $(function () {
            $("#userDialog").dialog({ autoOpen: false, width: 900, resizable: false });
            $("#userDialog").parent().appendTo(jQuery("form:first"));

            $("#passwordDialog").dialog({ autoOpen: false, width: 800, resizable: false });
            $("#passwordDialog").parent().appendTo(jQuery("form:first"));

            $("#detailDialog").dialog({ autoOpen: false, width: 800, resizable: false });
            $("#detailDialog").parent().appendTo(jQuery("form:first"));

            $(".ui-dialog-titlebar").hide();

            <%=this.JsCodeToRunOnReady%>;
        });

        function createUpdateForm(id) {
            __doPostBack('upUserDetails', id);
        }

        function showPasswordChange(id)
        {
            $('#tbPassword').val('');
            $('#tbVerifyPassword').val('');
            $('#hdUserId1').val(id);
            $('.passwordValidator').hide();
            $('#passwordDialog').dialog('open');
        }

        function AutoComplete() {
            if ($('#MainContent_txtUserName').val() == '') {
                if ($('#MainContent_txtFirstName').val() != '') {
                    var fist_name_letter = $('#MainContent_txtFirstName').val()[0];
                    $('#MainContent_txtUserName').val(fist_name_letter + $('#MainContent_txtLastName').val());
                }
            }
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    
            <div class="page_header">
                <h2><img src="<%=ResolveClientUrl("~") %>images/design/user_management_tt_icon.png" alt="" title="" /> User Management</h2>
            </div>
            
            <asp:UpdatePanel ID="upMain" runat="server" UpdateMode="Conditional">
            <ContentTemplate>

            <div class="search_panel">
                <div class="row">
                	<div class="col-lg-3">
                    	<div class="form-group">
                            <label class="control-label" for="inputLastName">Last Name</label>
                            <asp:TextBox runat="server" ID="txtLastNameFilter" CssClass="form-control" placeholder="Last Name"/>
                        </div>
                    </div>
                    <div class="col-lg-3">
                    	<div class="form-group">
                            <label class="control-label" for="inputEmail">Email</label>
                            <asp:TextBox runat="server" ID="txtEmailFilter" CssClass="form-control" placeholder="email"/>
                        </div>
                    </div>
                    <div class="col-lg-2">
                    	<label class="control-label" for="inputAccessLabel">Access Level</label>
                        <asp:DropDownList CssClass="form-control" ID="ddlIsAdminFilter" runat="server">
                            <asp:ListItem Text="ALL" Value="-1"/>
                            <asp:ListItem Text="Administrator" Value="1"/>
                            <asp:ListItem Text="Agent" Value="0"></asp:ListItem>
                        </asp:DropDownList>
                    </div>
                    
                    <div class="col-lg-2">
                    	<label class="control-label" for="inputStatus">Status</label>
                    	<asp:DropDownList CssClass="form-control" ID="ddlIsActiveFilter" runat="server">
                            <asp:ListItem Text="ALL" Value="-1"/>
                            <asp:ListItem Text="Active" Value="1"/>
                            <asp:ListItem Text="Inactive" Value="0"></asp:ListItem>
                        </asp:DropDownList>
                    </div>
                    <div class="col-lg-2">                    	
                        <asp:Button CssClass="btn btn-primary search_btn" ID="btnSearch" Text="Search" 
                            runat="server" onclick="btnSearch_Click" />
                    </div>
                    
                </div>
            </div>

        	<div class="page_container">
                <asp:Button CssClass="btn apps_btn apps_gray_btn" ID="btnAdd" Text="Add New" runat="server" OnClientClick="createUpdateForm(-1); return false;" />

                <div class="table-responsive">

                <asp:GridView ID="gridUsers" AutoGenerateColumns="false" runat="server" CssClass="table table-bordered table-hover"
                AllowPaging="True" PageSize="20" OnPageIndexChanging="gridUsers_PageIndexChanging" PreRender="gridUsers_PreRender">
                <PagerSettings Mode="Numeric" PageButtonCount="4" NextPageText=">" PreviousPageText="<"  FirstPageText="<<" LastPageText=">>"/>
                <Columns>
                    <asp:TemplateField HeaderText="First Name">
                        <ItemTemplate>
                            <asp:HiddenField ID="hidId" Value='<%#Eval("Id")%>' runat="server" />
                            <asp:Label ID="lblFirstName" Text='<%# Eval("FirstName") %>' runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Last Name">
                        <ItemTemplate>
                            <asp:Label ID="lblLastName" Text='<%# Eval("LastName") %>' runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="User Name">
                        <ItemTemplate>
                            <asp:Label ID="lblUserName" Text='<%# Eval("UserName") %>' runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Email">
                        <ItemTemplate>
                            <asp:Label ID="lblEmail" Text='<%# Eval("Email") %>' runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Access Level">
                        <ItemTemplate>
                            <asp:Label ID="lblIsAdmin" Text='<%#Eval("AccessLevelName")%>' runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Status">
                        <ItemTemplate>
                            <asp:Label ID="lblIsAcrive" Text='<%# Eval("StatusName").ToString() %>' runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    
                    <asp:TemplateField HeaderText="Action">
                        <ItemTemplate>
                            <a href='javascript:void(0)' onclick="javascript:createUpdateForm(<%#Eval("Id")%>);">
                                <img src="<%=ResolveClientUrl("~") %>images/design/actions_icon/edit_icon.png" alt="" title="Edit" border="0" />
                            </a>
                            <asp:ImageButton runat="server" ImageUrl="~/images/design/actions_icon/delete_icon.gif" ToolTip="Delete" Style="vertical-align:middle;"
                                ID="lbtnDelete" OnCommand="Users_Command" CommandName="delete" CommandArgument='<%# Eval("Id")%>' OnClientClick="return confirm('Please confirm if you want to delete user')" />
                            <a href='javascript:void(0)' onclick="javascript:showPasswordChange(<%#Eval("Id")%>);">
                                <img src="<%=ResolveClientUrl("~") %>images/design/actions_icon/password_icon.png" alt="" title="Change Password" border="0" />
                            </a>

                            <asp:LinkButton ID="lbtnDeactivate" OnCommand="Users_Command" Text="Deactivate"
                            Visible='<%# Eval("StatusName") == "Active" %>'
                            CommandName="deactivate" CommandArgument='<%# Eval("Id")%>' runat="server"
                            OnClientClick="return confirm('Please confirm if you want to deactivate user')" />

                            <asp:LinkButton ID="lbtnActivate" OnCommand="Users_Command" Text="Activate"
                            Visible='<%# Eval("StatusName") == "Inactive" %>'
                            CommandName="activate" CommandArgument='<%# Eval("Id")%>' runat="server"
                            OnClientClick="return confirm('Please confirm if you want to activate user')" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                </asp:GridView>
                </div>
            </div>

            </ContentTemplate>
                <Triggers>
                    <asp:PostBackTrigger ControlID="btnSearch" />
                </Triggers>
            </asp:UpdatePanel>

            <div id="userDialog" class="row">
                <asp:UpdatePanel runat="server" ID="upUserDetails" OnLoad="upUserDetails_Load" UpdateMode="Conditional" ClientIDMode="Static">
                <ContentTemplate>
                    <div class="fieldset_block col-lg-9 page_area" style="width:100%;">
                        <fieldset>
                            <legend><h4><asp:Label runat="server" ID="lblDialogTitle"></asp:Label></h4></legend>
                            <div class="fieldset_cotent form-horizontal">
                                <asp:Label runat="server" ID="hdUserId" style="display:none;" />
                                <div class="row">
                                	<div class="col-lg-6">                                    
                                    	<div class="form-group">
                                        	<label class="col-lg-4 control-label">First Name</label>
                                            <div class="col-lg-8">
                                                <asp:TextBox CssClass="form-control" placeholder="First Name" ID="txtFirstName" ValidationGroup="newUser" runat="server" TabIndex="1" />
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" ControlToValidate="txtFirstName" runat="server" Text="*" ValidationGroup="newUser" ForeColor="Red" />
                                            </div>
                                        </div>
                                    	<div class="form-group">
                                        	<label class="col-lg-4 control-label">Last Name</label>
                                            <div class="col-lg-8">
                                                <asp:TextBox CssClass="form-control" placeholder="Last Name" ID="txtLastName" ValidationGroup="newUser" runat="server" TabIndex="2" />
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator5" ControlToValidate="txtLastName" runat="server" Text="*" ValidationGroup="newUser" ForeColor="Red" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <asp:Label style="font-weight:bold; padding-left:76px" ID="lbActive" runat="server" Text="Label">Active</asp:Label>
                                            <asp:CheckBox style="margin-left:30px" ID="cbActive" runat="server" />
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-4 control-label"></label>
                                            <div class="col-lg-8">
                                                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" Display="Dynamic" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ValidationGroup="newUser" ControlToValidate="txtEmail" runat="server" Text="Invalid email" ForeColor="Red" />
                                            </div>
                                        </div>
                                    </div>
                                    
                                    <div class="col-lg-6">      
                                        <div class="form-group">
                                        	<label class="col-lg-4 control-label">Email</label>
                                            <div class="col-lg-8">
                                                <asp:TextBox CssClass="form-control" ID="txtEmail" ValidationGroup="newUser" placeholder="Email" runat="server" TabIndex="3" />
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtEmail" runat="server" ValidationGroup="newUser" Text="*" ForeColor="Red" />
                                            </div>
                                        </div>
                                        
                                        <div class="form-group">
                                        	    <label class="col-lg-4 control-label">Email Setting</label>
                                                <div class="col-lg-8">
                                                    <asp:DropDownList CssClass="form-control" ID="ddlEmailSettingId" runat="server" DataValueField="EmailSettingId" DataTextField="EmailSettingName"/>
                                                </div>
                                        </div>
                                                                                                              
                                        <div class="form-group">
                                        	<label class="col-lg-4 control-label">Access Level</label>
                                            <div class="col-lg-8">
                                                <asp:DropDownList CssClass="form-control" ID="ddlAccessLevel" runat="server" TabIndex="4">
                                                    <asp:ListItem Text="Administrator" Value="1"/>
                                                    <asp:ListItem Text="Agent" Value="0"></asp:ListItem>
                                                </asp:DropDownList>
                                            </div>
                                        </div>
                                        
                                        <div class="form-group">
                                        	<label class="col-lg-4 control-label">Username</label>
                                            <div class="col-lg-8">
                                                <asp:TextBox CssClass="form-control" placeholder="User Name" ID="txtUserName" ValidationGroup="newUser" runat="server" OnClick="javascript:AutoComplete()" onfocus="javascript:AutoComplete()" TabIndex="5" />
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" ControlToValidate="txtUserName" runat="server" Text="*" ValidationGroup="newUser" ForeColor="Red" />
                                            </div>
                                        </div>                                        
                                    </div>
                                    
                                </div>
                                <div class="button_group">
                                    <asp:Button CssClass="btn btn-success" ID="btnSaveUser"  ValidationGroup="newUser" Text="Save" runat="server" OnClick="btnSaveUser_Click" />
                                    <asp:Button CssClass="btn btn-info" ID="btnCancel" Text="Cancel" runat="server" OnClientClick="$('#userDialog').dialog('close'); return false;" />                                    
                                    <button class="btn btn-warning pull-right" type="button" id="lnkChangePassword" runat="server">Change Password</button>
                                </div> 
                            </div>
                        </fieldset>
                    </div>
                </ContentTemplate>
                    <Triggers>
                        <asp:PostBackTrigger ControlID="btnSaveUser" />
                    </Triggers>
                </asp:UpdatePanel>
            </div>
 
            <div id="detailDialog" class="row" style="display:none">
                <asp:UpdatePanel runat="server" ID="up_UserInformationDetail" UpdateMode="Conditional" ClientIDMode="Static">
                <ContentTemplate>
                    <div class="fieldset_block col-lg-9 page_area" style="width:50%;">
                        <fieldset>
                            <legend><h4><asp:Label runat="server" ID="lbldetailDialog"></asp:Label></h4></legend>
                            <div class="fieldset_cotent form-horizontal">
                                <asp:Label runat="server" ID="Label2" style="display:none;" />
                                <div class="row">                                    
                                    <asp:Label ID="UserNameDetail_text" runat="server"></asp:Label>
                                    <br />
                                    <asp:Label ID="UserPasswordDetail_text" runat="server"></asp:Label>
                                </div>
                                <div class="button_group">
                                    <asp:Button CssClass="btn btn-info" ID="Button2" Text="Close" runat="server" OnClientClick="$('#detailDialog').dialog('close')" />                                    
                                </div> 
                            </div>
                        </fieldset>
                    </div>
                </ContentTemplate>
                </asp:UpdatePanel>
            </div>

            <div id="passwordDialog" class="row">
            <asp:UpdatePanel runat="server" ID="upChangePassword" UpdateMode="Conditional" ClientIDMode="Static">
            <ContentTemplate>
                <div class="fieldset_block col-lg-9 page_area" style="width:100%;">
                <fieldset>
                    <legend><h4>Change Password</h4></legend>
                    <div class="fieldset_cotent form-horizontal">
                        <asp:HiddenField runat="server" ID="hdUserId1" ClientIDMode="Static"/>
                        <div class="row">
                            <div class="col-lg-12">                                    
                                <div class="form-group">
                                    <label class="col-lg-3 control-label">New Password</label>
                                    <div class="col-lg-3">
                                        <asp:TextBox ID="tbPassword" runat="server" TextMode="Password" CssClass="form-control" ClientIDMode="Static"></asp:TextBox>
                                    </div>
                                    <div class="col-lg-6">
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="tbPassword" CssClass="validator passwordValidator"
                                            Display="Dynamic" ErrorMessage="Passwor is required" ValidationGroup="changePassword" ForeColor="Red"></asp:RequiredFieldValidator>
                                        <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="tbPassword" CssClass="validator passwordValidator"
                                            Display="Dynamic" ErrorMessage="Allow only letters and numbers, from 5 to 15 symbols)" ForeColor="Red"
                                            ValidationExpression="^[a-zA-Z0-9\s]{5,15}$" ValidationGroup="changePassword"></asp:RegularExpressionValidator>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-lg-3 control-label">Verify Password</label>
                                    <div class="col-lg-3">
                                        <asp:TextBox ID="tbVerifyPassword" runat="server" TextMode="Password" CssClass="form-control" ClientIDMode="Static"></asp:TextBox>
                                    </div>
                                    <div class="col-lg-6">
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="tbVerifyPassword" CssClass="validator passwordValidator"
                                            Display="Dynamic" ErrorMessage="Verify passwor is required" ValidationGroup="changePassword" ForeColor="Red"></asp:RequiredFieldValidator>
                                        <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="tbPassword"
                                            ControlToValidate="tbVerifyPassword" Display="Dynamic" 
                                            ErrorMessage="Password and Verify Password values do not match" 
                                            ValidationGroup="changePassword" CssClass="validator passwordValidator" ForeColor="Red"></asp:CompareValidator>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="button_group">
                            <asp:Button CssClass="btn btn-success" ID="btnSavePassword"  ValidationGroup="changePassword" Text="Save" runat="server" OnClick="btnSavePassword_Click" />
                            <asp:Button CssClass="btn btn-info" ID="btnCancelPassword" Text="Cancel" runat="server" OnClientClick="$('#passwordDialog').dialog('close'); return false;" CausesValidation="false" />
                        </div> 
                    </div>
                </fieldset>
                </div>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnSavePassword" EventName="Click" />
            </Triggers>
            </asp:UpdatePanel>
            </div>

</asp:Content>
